home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / Sample Code / Sample Editors⁄Viewers / Text Editor / Source / TextEditorUtils.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-13  |  8.1 KB  |  337 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        TextEditorUtils.h
  3.  
  4.     Contains:    TextEditor utility functions & classes
  5.  
  6.     Written by:    Steve Smith
  7.  
  8.     Copyright:    © 1994 - 1995 by Apple Computer, Inc., all rights reserved.
  9. */
  10.  
  11. #ifndef _TEXTEDITORUTILS_
  12. #define _TEXTEDITORUTILS_
  13.  
  14. #ifndef _COMPILERDEFS_
  15. #include "CompDefs.h"
  16. #endif
  17.  
  18. // -- OpenDoc Utilities --
  19.  
  20. #ifndef _EXCEPT_
  21. // Exceptions define several important macros (ie. CHECKENV)
  22. // which are used in the SOM method dispatch glue. If Except.h
  23. // is not included early enough, exceptions may not be thrown
  24. // correctly when returning from a SOM method with "ev" parameter set.
  25. #include <Except.h>
  26. #endif
  27.  
  28. // -- TextEditor Includes --
  29.  
  30. #ifndef _SAMPLECOLLECTIONS_
  31. #include "SampleCollections.h"
  32. #endif
  33.  
  34. // -- OpenDoc Includes --
  35.  
  36. #ifndef _ODTYPES_
  37. #include <ODTypes.h>
  38. #endif
  39.  
  40. #ifndef SOM_ODFrame_xh
  41. #include <Frame.xh>
  42. #endif
  43.  
  44. // -- OpenDoc Utilities --
  45.  
  46. #ifndef _ITEXT_
  47. #include <IText.h>
  48. #endif
  49.  
  50. #ifndef _ODUTILS_
  51. #include <ODUtils.h>
  52. #endif
  53.  
  54. #ifndef _ODDEBUG_
  55. #include <ODDebug.h>
  56. #endif
  57.  
  58. #ifndef _TEMPOBJ_
  59. #include <TempObj.h>
  60. #endif
  61.  
  62. // -- Macintosh Includes --
  63.  
  64. #ifndef __TYPES__
  65. #include <Types.h>
  66. #endif
  67.  
  68. // -- Textension Includes --
  69.  
  70. #ifndef _TextensionCommon_
  71. #include "TextensionCommon.h"
  72. #endif
  73.  
  74. // -- Forward Declarations --
  75. class ODDraft;
  76. class ODFacet;
  77. class ODWindow;
  78. class ODStorageUnitView;
  79.  
  80. class CTextension;
  81. class SampleCode_TextEditor;
  82.  
  83. //------------------------------------------------------------------------------
  84. // Typedefs
  85. //------------------------------------------------------------------------------
  86.  
  87. struct ScrollDataRec {
  88.     ControlHandle            vScrollbar;
  89.     ControlHandle            hScrollbar;
  90.     ODFrame*                frame;
  91.     CTextension*            textension;
  92.     SampleCode_TextEditor*    textEditor;
  93. };
  94.  
  95. struct FINF {
  96.     short    font;
  97.     short    face;
  98.     short    size;
  99. };
  100.  
  101. typedef struct FINF *FINFPtr;
  102.  
  103. //------------------------------------------------------------------------------
  104. // Function Prototypes
  105. //------------------------------------------------------------------------------
  106.  
  107. ODIText*        GetPartName(Environment* ev, ODPart* part, ODType category);
  108. ODBoolean        NamesAreEquivalent(Environment* ev, ODIText* fileName,
  109.                                         ODIText* partName);
  110. void            GetEditorScriptLanguage(Environment* ev, ODScriptCode* script,
  111.                                         ODLangCode* language);
  112.  
  113. void            LoadIcons(Environment* ev, ODUShort whichSuite, Handle* suite);
  114. void            LoadThumbnail(Environment* ev, Handle* thumbnail);
  115.  
  116. Rect            TilePartWindow(Environment* ev, Rect* facetBounds,
  117.                                         Rect* partWindowBounds);
  118.  
  119. ODUShort        CountFacets(Environment* ev, ODFrame* frame);
  120.  
  121. void            TranslateData(Environment* ev, ODStorageUnit* fromSU, ODStorageUnit* toSU,
  122.                                         ODType translateKind, ODType desiredKind);
  123.  
  124. FINF            GetIndFINF(short id, short num);
  125. void            SetDialogDefaults(DialogPtr dialog, ODUShort finfID, ODUShort index);
  126.  
  127. void            FixedToIntRect(ODRect& fixedRect, Rect& intRect);
  128. void            IntToFixedRect(Rect& intRect, ODRect& fixedRect);
  129. void            LongToFixedRect(TLongRect& longRect, ODRect& fixedRect);
  130.  
  131. void            SetMenuCommandIndString(Environment* ev, ODCommandID command, 
  132.                                         ODSShort resID, ODSShort index);
  133.  
  134. ODUShort        ConvertNumStrToPixels(Str255 value);
  135. void            ConvertPixelsToNumStr(ODUShort value, Str255* numStr);
  136.  
  137. extern pascal    void ScrollProc(ControlHandle control, short partCode);
  138. extern void        ClickLoopProc(unsigned short message, void* data, void* refcon);
  139.  
  140. ODBoolean        KeyCausesModification(EventRecord* event);
  141. extern pascal    ODBoolean OtherDialogFilter(DialogPtr dialog, EventRecord* event, 
  142.                                         short* itemHit);
  143.  
  144. //=========================================================================
  145. // Utility Class Definitions
  146. //=========================================================================
  147.  
  148. //-------------------------------------------------------------------------
  149. // CFrameProxy
  150. //-------------------------------------------------------------------------
  151. class CFrameProxy // (aka CFuton)
  152. {
  153.     public:
  154.     CFrameProxy();
  155.     ~CFrameProxy();
  156.     
  157.     void        InitFrameProxy(ODID frameID, ODDraft* draft);
  158.     void        InitFrameProxy(Environment* ev, ODFrame* frame);
  159.     void        Purge(Environment* ev);
  160.  
  161.     ODFrame*    GetFrame(Environment* ev);
  162.     void        SetFrame(Environment* ev, ODFrame* frame);
  163.     ODBoolean    FrameIsLoaded(Environment* ev);
  164.     ODID        GetID();
  165.     ODDraft*    GetDraft();
  166.     
  167.     private:
  168.     ODFrame*    fFrame;
  169.     ODDraft*    fDraft;
  170.     ODID        fID;
  171. };
  172.  
  173. //-------------------------------------------------------------------------
  174. // CFrameInfo
  175. //-------------------------------------------------------------------------
  176. class CFrameInfo
  177. {
  178.     public:
  179.             CFrameInfo(ODSession* session);
  180.             ~CFrameInfo();
  181.     
  182.     void    Externalize(Environment* ev, ODStorageUnitView* storageUnitView);
  183.     void    CleanseFrameInfoProperty(Environment* ev, ODStorageUnit* storageUnit);
  184.     void    ExternalizeFrameInfo(Environment* ev, ODStorageUnit* storageUnit,
  185.                                     ODDraftKey key, ODFrame* scopeFrame);
  186.     void    CloneInto(Environment *ev, ODDraftKey key,
  187.                                     ODStorageUnitView* storageUnitView,
  188.                                     ODFrame* scopeFrame);
  189.     void    InitFromStorage(Environment* ev, ODStorageUnitView* storageUnitView);
  190.                 
  191.     ODBoolean        IsFrameActive();
  192.     void            SetFrameActive(ODBoolean active);
  193.     ODBoolean        FrameNeedsReactivating();
  194.     void            SetFrameReactivate(ODBoolean reactivate);
  195.     ODFacet*        GetActiveFacet();
  196.     void            SetActiveFacet(ODFacet* facet);
  197.     void            SetSourceFrame(Environment* ev, ODFrame* frame);
  198.     ODFrame*        GetSourceFrame(Environment* ev);
  199.     void            ReleaseSourceFrame(Environment* ev);
  200.     ODBoolean        HasSourceFrame();
  201.     ODWindow*        AcquirePartWindow(Environment* ev);
  202.     void            SetPartWindow(Environment* ev, ODWindow* window);
  203.     void            SetDependentFrame(Environment* ev, ODFrame* frame);
  204.     ODFrame*        GetDependentFrame(Environment* ev);
  205.     ODBoolean        HasDependentFrame();
  206.     void            ReleaseDependentFrame(Environment* ev);
  207.     void            SetShouldDisposeWindow(ODBoolean should);
  208.     ODBoolean        ShouldDisposeWindow();
  209.     
  210.     private:
  211.     CFrameInfo(); /* don't want parts to call */
  212.  
  213.     ODSession*        fSession;
  214.     ODFacet*        fActiveFacet;
  215.     CFrameProxy*    fSourceFrame;
  216.     CFrameProxy*    fDependentFrame;
  217.     ODID            fPartWindowID;
  218.     ODBoolean        fFrameActive;
  219.     ODBoolean        fFrameReactivate;
  220.     ODBoolean        fShouldDisposeWindow;
  221. };
  222.  
  223. //=========================================================================
  224. // Inline methods
  225. //=========================================================================
  226.  
  227. //-------------------------------------------------------------------------
  228. // CFrameProxy
  229. //-------------------------------------------------------------------------
  230.  
  231. inline CFrameProxy::CFrameProxy()
  232. {
  233.     fFrame = kODNULL;
  234.     fID = kODNULLID;
  235.     fDraft = kODNULL;
  236. }
  237.     
  238. inline CFrameProxy::~CFrameProxy()
  239. {
  240.     ODSafeReleaseObject(fFrame);
  241. }
  242.     
  243. inline void CFrameProxy::InitFrameProxy(ODID frameID, ODDraft* draft)
  244. {
  245.     ASSERT(draft!=kODNULL, kODErrIllegalNullInput);
  246.     
  247.     fFrame = kODNULL;
  248.     fID = frameID;
  249.     fDraft = draft;
  250. }
  251.     
  252. inline void CFrameProxy::InitFrameProxy(Environment* ev, ODFrame* frame)
  253. {
  254.     ASSERT(frame!=kODNULL, kODErrIllegalNullFrameInput);
  255.     
  256.     this->SetFrame(ev,frame);
  257. }
  258.  
  259. inline ODID CFrameProxy::GetID()
  260. {
  261.     return fID;
  262. }
  263.  
  264. inline ODDraft* CFrameProxy::GetDraft()
  265. {
  266.     return fDraft;
  267. }
  268.  
  269.  
  270. //-------------------------------------------------------------------------
  271. // CFrameInfo
  272. //-------------------------------------------------------------------------
  273.  
  274. inline ODBoolean CFrameInfo::IsFrameActive()
  275. {
  276.     return fFrameActive;
  277. }
  278.  
  279. inline void CFrameInfo::SetFrameActive(ODBoolean active)
  280. {
  281.     fFrameActive = active;
  282. }
  283.  
  284. inline ODBoolean CFrameInfo::FrameNeedsReactivating()
  285. {
  286.     return fFrameReactivate;
  287. }
  288.  
  289. inline void CFrameInfo::SetFrameReactivate(ODBoolean reactivate)
  290. {
  291.     fFrameReactivate = reactivate;
  292. }
  293.  
  294. inline ODFacet* CFrameInfo::GetActiveFacet()
  295. {
  296.     return fActiveFacet;
  297. }
  298.  
  299. inline void CFrameInfo::SetActiveFacet(ODFacet* facet)
  300. {
  301.     fActiveFacet = facet;
  302. }
  303.  
  304. inline ODFrame* CFrameInfo::GetSourceFrame(Environment* ev)
  305. {
  306.     return (fSourceFrame->GetFrame(ev));
  307. }
  308.  
  309. inline ODBoolean CFrameInfo::HasSourceFrame()
  310. {
  311.     return (fSourceFrame != kODNULL);
  312. }
  313.  
  314. inline ODFrame* CFrameInfo::GetDependentFrame(Environment* ev)
  315. {
  316.     return (fDependentFrame->GetFrame(ev));
  317. }
  318.  
  319. inline ODBoolean CFrameInfo::HasDependentFrame()
  320. {
  321.     return (fDependentFrame != kODNULL);
  322. }
  323.  
  324. inline void CFrameInfo::SetShouldDisposeWindow(ODBoolean should)
  325. {
  326.     fShouldDisposeWindow = should;
  327. }
  328.  
  329. inline ODBoolean CFrameInfo::ShouldDisposeWindow()
  330. {
  331.     return fShouldDisposeWindow;
  332. }
  333.  
  334.  
  335. #endif
  336.  
  337.